﻿
using Fozzy.Being;
using Fozzy.Gedcom;
using System.Collections.Generic;
namespace Fozzy.Family
{
    public class Family                                                 : Fozzy.Gedcom.Family
    {
        #region States
            public bool     Have_Parents                                { get { return this.Exist(Parents)                          ; } }
        #endregion

        #region Properties
            private Fozzy.Being.Person              Father              { get { return Parents.Father                               ; } }
            private Fozzy.Being.Person              Mother              { get { return Parents.Mother                               ; } }
            public Fozzy.Being.Person               Primary             { get { return this.Exist(Father) ? Father : Mother         ; } }
            public IEnumerable<Fozzy.Being.Parents> PossibleParentSets  { get { return null                                         ; } }
            private Fozzy.Being.Marriage            Marriage            { get { return Parents.Marriage                             ; } }
            public  IEnumerable<Partner>            Partners            { get { return Parents.Partners                             ; } }
        #endregion

        #region Constructeur
            public Family()
            {}
            public Family(_Element element)                              : base(element)
            {}
            public Family(Gedcom.Parents parents, Gedcom.Children children) : base(parents, children)
            {}
        #endregion

            //, new Relation_Couple(family), new Relation_Child(family)
            public override void Relate(IConcept target)
            {
                Person person = (Person)target                          ;
                Relate_Parents(person)                                  ;
                Relate_Children(person)                                 ;
            }

            private void Relate_Parents(Person target)
            {
                if (Father.Be(target)) target.Relate(new Couple(Mother));
                if (Mother.Be(target)) target.Relate(new Couple(Father)); 
            }

            private void Relate_Children(Person target)
            {
                foreach (Person child in Children) target.Relate(new Relation_Child(child));
            }

            public void Start(Fozzy.Time.Date date)
            {
                Set(new Fozzy.Gedcom.Marriage(date))                                ;
            }

            public void End(Fozzy.Time.Date date)
            {
                Set(new Fozzy.Gedcom.Divorce(date))                                 ;
            }

            private void Set(Fozzy.Being.Marriage marriage)
            {
                Parents.Set(marriage)                                               ;
            }

            private void Set(Fozzy.Being.Divorce divorce)
            {
                Marriage.Set(divorce)                                               ;
            }
    }

}
